﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AdmBase;
using Guedes_Library;

public partial class admin_pages_faq_Novo : TelaBase
{
    private FaqBusiness business;

    public FaqBusiness Business
    {
        get { 
            if(business == null)
                 business = new FaqBusiness();
            return business; }
        set { business = value; }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        IsLogado();
        string id = Request.QueryString["id"];
        if (id != null && !IsPostBack)
        {
            faq f = Business.GetById(int.Parse(id));
            if (f == null)
                Response.Redirect("~/admin/pages/faq/Default.aspx");
            txtDica.Text = f.Dica;
            txtTitulo.Text = f.Titulo;
            hdId.Value = f.ID.ToString();
        }
    }

    protected void Save(object sender, EventArgs e)
    {
        Retorno retorno;
        retorno = Business.Salvar(hdId.Value, txtTitulo.Text, txtDica.Text);
        ShowMensagem("Atenção", retorno.Mensagem);
        if (!retorno.Error)
            LimpaCampo();
    }

    public void LimpaCampo()
    {
        txtDica.Text = String.Empty;
        txtTitulo.Text = String.Empty;
        hdId.Value = String.Empty;
    }
}